<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	//搜索
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$fields=array('id','title','logo','desc');
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['num']){
		$psize = $_RQ['num'];
	}else{
		$psize = 15;
	}
	$total='';
	$parameter=array(
		'params'=>$params,
		'fields'=>$fields,
		'limit'=>array($pindex,$psize),
	);
	$list=pdo_getslice('jy_weishop_grass_group',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'文章分类列表'),
		),
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'logo','title'=>'分类图标','type'=>'image'),
			array('name'=>'title','title'=>'分类标题','type'=>'string'),
		),'action'=>array(
			array('type'=>'href','op'=>'edit','title'=>'翻译'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='edit'){
	$return=array();
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		$isset=$this->pdo_get('grass_group',array('fromid'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$data=array(
			'title'=>$post['title'],
			'diy'=>ijson_encode($post['diy'])
		);
		if($isset){
			$this->pdo_update('grass_group',$data,array('fromid'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['fromid']=$id;
			$this->pdo_insert('grass_group',$data);
		}
		exi('设置成功');
	}
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_weishop_grass_group',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		exi('请选择内容','error');	
	}
	$return['item']=$item;
	$isset=$this->pdo_get('grass_group',array('fromid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$item['diy']=json_decode($isset['diy'],true);
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'desc'=>'翻译内容',
		'edit_tab'=>true,
		'edits'=>array(),
	);
	$list=array(
		array('name'=>'title','tip'=>'标题','type'=>'stringdiy'),
	);
	$is_langs=str_array($this->setting['is_langs']);
	foreach($is_langs as $en){
		$one=array();
		$one['title']=$this->langs[$en];
		$one['list']=array();
		$one['list'][]=array('type'=>'jsup','title'=>'一键翻译本页内容','action'=>'jy_lang_weishop/index/upfanyi/en='.$en,'message'=>'确定要一键翻译吗？这样将覆盖原有设置','btntitle'=>'一键翻译');
		foreach($list as $fv){
			$fv['title']=$item[$fv['name']];
			$fv['name']='diy.'.$en.'_'.$fv['name'];
			$one['list'][]=$fv;
		}
		$htmls['edits'][]=$one;
	}
	$return['item']['fanyidata']=array();
	foreach($list as $k=>$fv){
		$return['item']['fanyidata']['_'.$fv['name']]=$fv['title'];
	}
	$return['htmls']=$htmls;
	exi($return);
}


?>